//
//  GBUtilsTestTests.m
//  GBUtilsTestTests
//
//  Created by wanglidong on 14-5-6.
//  Copyright (c) 2014年 GoldenBull. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "GTMBase64.h"
#import "GBTick.h"

@interface GBUtilsTestTests : XCTestCase

@end

@implementation GBUtilsTestTests

- (void)setUp
{
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown
{
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testNSProcessInfo
{
    id tick = [[NSUserDefaults standardUserDefaults] objectForKey:@"NSProcessInfo"];
    
    double tn = [[NSProcessInfo processInfo] systemUptime];
    if (tick) {
        
        double t1 = [tick doubleValue];
        
        NSLog(@"%s diff : %f - %f= %f",__PRETTY_FUNCTION__,tn,t1,tn-t1);
        
        [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithDouble:tn] forKey:@"NSProcessInfo"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    else
    {
        NSLog(@"%s first time : %f",__PRETTY_FUNCTION__,tn);
        [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithDouble:tn] forKey:@"NSProcessInfo"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}

- (void)testGBTick
{
    id tick = [[NSUserDefaults standardUserDefaults] objectForKey:@"tick"];
    
    uint64_t tn = [GBTick milliSecond];
    if (tick) {
        
        uint64_t t1 = [tick unsignedLongLongValue];
        
        NSLog(@"%s diff : %lld - %lld= %lld",__PRETTY_FUNCTION__,tn,t1,tn-t1);
        
        [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithUnsignedLongLong:tn] forKey:@"tick"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    else
    {
        NSLog(@"%s first time : %lld",__PRETTY_FUNCTION__,tn);
        [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithUnsignedLongLong:tn] forKey:@"tick"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}

- (void)testGTMBase64
{
    NSString *src = @"this is a test string.";
    NSData *data = [GTMBase64 encodeBytes:[src UTF8String] length:[src length]];
    NSLog(@"\n\nsrc:%@\n\nencodeBytes:%s\n\n",src,[data bytes]);
    NSLog(@"\n\ndata:%s\n\ndecodeBytes:%s\n\n",[data bytes],[[GTMBase64 decodeData:data] bytes]);
}

@end
